package com.example.fsd.controller.news;
import com.example.fsd.common.result.R;
import com.example.fsd.pojo.News;
import com.example.fsd.service.news.INewsService;
import com.example.fsd.utils.ImageUpdate;
import com.example.fsd.vo.PageVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangguihong
 * @since 2024-11-22
 */
@RestController
@RequestMapping("/news")
@RequiredArgsConstructor
public class NewsController {
    private  final INewsService newsService;
    private final ImageUpdate imageUpdate;

    @GetMapping("/listNewsPage")
    private R listNewsPage(PageVo pageVo){
        return newsService.listNewsPage(pageVo);
    }
    @GetMapping("/findNewsById/{id}")
    private R findNewsById(@PathVariable Integer id){
        return newsService.findNewsById(id);
    }

    @GetMapping("/findNewsnextById/{id}")
    private R findNewsnextById(@PathVariable Integer id){
        return newsService.findNewsnextById(id);
    }

    @GetMapping("/findNewsprevById/{id}")
    private R findNewsprevById(@PathVariable Integer id){
        return newsService.findNewsprevById(id);
    }

    @PostMapping("/updateNewsxqImg")
    private R updateCasexqImg(MultipartFile file, Integer id) {
        return newsService.updateNewsxqImg(file, id);
    }
    @PutMapping("/updateNews")
    private R updateJdal(@RequestBody News news) {
        return newsService.updatenews(news);
    }
    @GetMapping("/listALlNews")
    private R listALlNews(){
        return newsService.listALlNews();
    }
    @PostMapping("/addNews")
    private R addNews(@RequestBody News news) {
        return newsService.addNews(news);
    }
    @PostMapping("handleImage")
    private R handleImage(@RequestParam("file") MultipartFile file) {
        return imageUpdate.updateImage(file);
    }

}
